package com.chen.shopping_search_customer_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chen.shopping_common.pojo.GoodsDesc;
import com.chen.shopping_common.pojo.GoodsSearchParam;
import com.chen.shopping_common.pojo.GoodsSearchResult;
import com.chen.shopping_common.result.BaseResult;
import com.chen.shopping_common.service.GoodsService;
import com.chen.shopping_common.service.SearchService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/goodsSearch")
public class SearchController {

    @DubboReference
    private SearchService service;
    @DubboReference
    private GoodsService goodsService;

    @GetMapping("/autoSuggest")
    public BaseResult<List<String>> autoSuggest(String keyword){
        List<String> list = service.autoSuggest(keyword);
        return BaseResult.ok(list);

    }

    @PostMapping("/search")
    public BaseResult<GoodsSearchResult> search(@RequestBody GoodsSearchParam goodsSearchParam){
        GoodsSearchResult search = service.search(goodsSearchParam);
        return BaseResult.ok(search);
    }

    @GetMapping("/findDesc")
    public BaseResult<GoodsDesc> findById(Long id){
        GoodsDesc descById = goodsService.findDescById(id);
        return BaseResult.ok(descById);
    }

}
